﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DevExpress.XtraGrid.Views.Grid;
using QuanLyKho.PhongMau;

namespace QuanLyKho.Control
{
    public partial class Phongmau_Xuatkho : UserControl
    {
        public Phongmau_Xuatkho()
        {
            InitializeComponent();
            Loaddata();
            SetPropertiesGrid();
        }

        public void Loaddata()
        {
            DataTable data = DataAll.SelectAll("PhongMau_KhongDuyet", "*", " WHERE TrangThai = " + Convert.ToInt32(TrangThai.PhongMau_TaoMoi));
            gridXuatKho.DataSource = data;
            SetPropertiesGrid();
        }

        public void SetPropertiesGrid()
        {
            gvXuatKho.BestFitColumns();
            gvXuatKho.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
            gvXuatKho.OptionsBehavior.Editable = false;
            gvXuatKho.OptionsSelection.EnableAppearanceFocusedCell = false;
            gvXuatKho.OptionsSelection.MultiSelect = true;
            gvXuatKho.OptionsView.ShowGroupPanel = false;
            //gvNhapKho.OptionsView.ColumnAutoWidth = false;
            gvXuatKho.OptionsView.ShowFooter = true;
            gvXuatKho.OptionsFind.AlwaysVisible = true;
            SetPropertiesColumns();
        }

        public void SetPropertiesColumns()
        {
            gvXuatKho.Columns["MaIDNhapKho"].Visible = false;
            gvXuatKho.Columns["MaNhapKho"].Visible = false;
        }

        private void bntThemMoi_Click(object sender, EventArgs e)
        {
            var xuatkho = new Phongmau_XuatkhoPopup();
            xuatkho.ShowDialog();
            Loaddata();
        }

        private void gvXuatKho_DoubleClick(object sender, EventArgs e)
        {
            if (gvXuatKho.FocusedRowHandle >= 0)
            {
                Phongmau_XuatkhoPopup.MaID = gvXuatKho.Columns["MaIDNhapKho"].View.GetRowCellDisplayText(gvXuatKho.FocusedRowHandle, "MaIDNhapKho");
                var nhapkho = new Phongmau_XuatkhoPopup();
                nhapkho.ShowDialog();
                Loaddata();
                Phongmau_XuatkhoPopup.MaID = "0";
            } 
        }
    }
}
